<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>key的作用</title>
  </head>
  <body>
    <div id="app">
      <p v-for="item in items" :key="item">{{item}}</p>
    </div>

    <script src="../../dist/vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: { items: ["a", "b", "c", "d", "e"] },
        mounted() {
          // 2秒后在 c 前面插入 f
          setTimeout(() => {
            this.items.splice(2, 0, "f");
          }, 2000);
        },
      });
    </script>
  </body>
</html>
